//
//  MyInfoViewController.m
//  吃货·上海
//
//  Created by 高青松 on 15/11/27.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "MyInfoViewController.h"
#import "UIImageView+WebCache.h"

#import <BmobSDK/Bmob.h>
#import <BmobSDK/BmobProFile.h>
@interface MyInfoViewController ()<UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>
{
    
    NSArray *dataSource;
}
@property (nonatomic,strong)UIView *iconAndNameView;
@property (nonatomic,strong)UIView *signView;
@property (nonatomic,strong)UIView *pwView;
@property (nonatomic,strong)UIView *userView;
@property (nonatomic,strong)UIView *aboutView;


@property (nonatomic,strong) UIImageView *iconImage;
@property (nonatomic,strong) UITextField *nameTF;
@property (nonatomic,strong) UITextView *signTV;
@property (nonatomic,strong) UITextField *pwTF;
@property (nonatomic, strong)UITextField *cwpTF;

@property (nonatomic, strong)NSString *nowTime;
@end

@implementation MyInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"个人中心";
    
    BmobUser *bUser = [BmobUser getCurrentUser];
    self.mineModel = [[MineModel alloc]initWithUserModel:bUser];
    
    self.personalTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 44+20, KScreenWidth, KScreenHeight-20-44-49) style:UITableViewStyleGrouped];
    [self.view addSubview:_personalTableView];
    self.personalTableView.delegate=self;
    self.personalTableView.dataSource=self;
    self.personalTableView.bounces=NO;
    self.personalTableView.showsVerticalScrollIndicator = NO;//不显示右侧滑块
    self.personalTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;//分割线
    dataSource=@[@"清除缓存",@"密码管理",@"用户协议",@"关于"];
    
}
#pragma mark tableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //分组数 也就是section数
    return 3;
}

//设置每个分组下tableview的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else if (section==1) {
        return dataSource.count;
    }else{
        return 1;
    }
}
//每个分组上边预留的空白高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 20;
}
//每个分组下边预留的空白高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section==2) {
        return 40;
    }
    return 20;
}
//每一个分组下对应的tableview 高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 80;
    }
    return 40;
}

//设置每行对应的cell（展示的内容）
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifer=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    
    if (indexPath.section==0) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"userinfo"];
        
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake((KScreenWidth - 80) / 2, 0, 80, 80)];
        imageView.layer.cornerRadius = 40;
        [imageView.layer setMasksToBounds:YES];
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.mineModel.userImageStr] placeholderImage:[UIImage imageNamed:@"icon"]];
        [cell.contentView addSubview:imageView];
        
        /*
        UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, 60, 80)];
        nameLabel.text= self.mineModel.otherName;
        [cell.contentView addSubview:nameLabel];
         */
    }else if (indexPath.section==1) {
        cell.textLabel.text=[dataSource objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
    }else{
        cell.textLabel.text=@"退出";
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

// 点击cell方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        [self setIconAndNameView];
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            [self setSignTF];
        }
        if (indexPath.row == 1) {
            [self setPwTF];
        }
        if (indexPath.row == 2) {
            [self setUserView];
        }
        if (indexPath.row == 3) {
            [self setAboutView];
        }
    }
    if (indexPath.section == 2)
    {
        //[BmobUser logout];
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }
}


// 相关信息
- (void)setAboutView
{
    self.aboutView = [[UIView alloc]initWithFrame:CGRectMake((KScreenWidth - 300)/2, 200/2, 300, 250)];
    self.aboutView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.aboutView];
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 70, 260, 90)];
    //label.center = self.aboutView.center;
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"吃货·上海 版本号1.0\n吃货·上海版权归上海市东成西就有限公司所有";
    [self.aboutView addSubview:label];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(aboutTap:)];
    [self.aboutView addGestureRecognizer:tap];
}

- (void)aboutTap:(UITapGestureRecognizer *)tap
{
    self.aboutView.hidden = YES;
}

// 用户协议
- (void)setUserView
{
    self.userView = [[UIView alloc]initWithFrame:CGRectMake(50/2, 50, KScreenWidth -50, KScreenHeight - 150)];
    self.userView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.userView];
    UITextView *userTV = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth - 50, KScreenHeight - 220)];
    [self setUserTextView:userTV];
    [self.userView addSubview:userTV];
    // 确定button
    UIButton *determineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    determineBtn.frame = CGRectMake(150, KScreenHeight - 200, 60, 30);
    determineBtn.backgroundColor = KColor;
    [determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    determineBtn.layer.cornerRadius = 10;
    determineBtn.layer.masksToBounds = YES;
    [determineBtn addTarget:self action:@selector(cancelBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.userView addSubview:determineBtn];
    
}

- (void)cancelBtn:(UIButton *)btn
{
    self.userView.hidden = YES;
}
// 更改密码界面
- (void)setPwTF
{
    self.pwView = [[UIView alloc]initWithFrame:CGRectMake((KScreenWidth - 300)/2, 200/2, 300, 250)];
    self.pwView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.pwView];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 80, 30)];
    label.text = @"重设密码";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = KColor;
    [self.pwView addSubview:label];

    
    UILabel *clabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 120, 80, 30)];
    clabel.text = @"确定密码";
    clabel.textAlignment = NSTextAlignmentCenter;
    clabel.textColor = KColor;
    [self.pwView addSubview:clabel];
    
    
    self.pwTF = [[UITextField alloc]initWithFrame:CGRectMake(100, 50, 180, 30)];
    self.pwTF.placeholder = @"请输入密码";
    self.pwTF.backgroundColor = KMyColor;
    [self.pwView addSubview:self.pwTF];
    
    self.cwpTF = [[UITextField alloc]initWithFrame:CGRectMake(100, 120, 180, 30)];
    self.cwpTF.placeholder = @"请确定输入密码";
    self.cwpTF.backgroundColor = KMyColor;
    [self.pwView addSubview:_cwpTF];
    
    
    // 确定更改的button
    UIButton *determineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    determineBtn.frame = CGRectMake(160, 200, 100, 30);
    determineBtn.backgroundColor = KColor;
    [determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    determineBtn.layer.cornerRadius = 10;
    determineBtn.layer.masksToBounds = YES;
    [determineBtn addTarget:self action:@selector(cpwBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.pwView addSubview:determineBtn];
    
    // 确定更改的button
    UIButton *defBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    defBtn.frame = CGRectMake(40, 200, 100, 30);
    defBtn.backgroundColor = KColor;
    [defBtn setTitle:@"取消" forState:UIControlStateNormal];
    defBtn.layer.cornerRadius = 10;
    defBtn.layer.masksToBounds = YES;
    [defBtn addTarget:self action:@selector(defBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.pwView addSubview:defBtn];
    
}

// 更改密码的取消和确定
- (void)defBtn:(UIButton *)btn
{
    self.pwView.hidden = YES;
    self.iconAndNameView.hidden = YES;
}
- (void)cpwBtn:(UIBarButtonItem *)btn
{
    NSLog(@"self.pwtf ==== %@", self.pwTF.text);
    if ([self.pwTF.text isEqualToString:@""])
    {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"密码不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        return;
    }
    
    if (![self.pwTF.text isEqualToString:self.cwpTF.text]) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"两次密码不相同,请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        return;
    }
    
    BmobUser *bUser = [BmobUser getCurrentUser];
    if (!bUser)
    {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请先登录" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        return;
    }
    [bUser setObject:self.pwTF.text forKey:@"password"];
    [bUser updateInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
        if (isSuccessful) {
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
            label.center = self.iconAndNameView.center;
            label.center = self.signView.center;
            label.text = @"数据已更新";
            label.alpha = 0;
            [self.view addSubview:label];
            [UIView animateWithDuration:0.5 animations:^{
                label.alpha = 1;
            } completion:^(BOOL finished) {
                if (finished) {
                    [UIView animateWithDuration:0.5 animations:^{
                        label.alpha = 0;
                        
                    }];
                    self.pwView.hidden = YES;
                }
            }];
        }
        if (error) 
        {
            self.pwView.hidden = YES;
        }
    }];
}


// 输入个性签名
- (void)setSignTF
{

   // 计算整个目录下缓存的大小
    NSString *diskCachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
    float totalSize;
    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath];
    for (NSString *fileName in fileEnumerator)
    {
        NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName];
        
        NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
        
        unsigned long long length = [attrs fileSize];
        
        totalSize += length / 1024.0 / 1024.0;
    }
    // 清除缓存
    [[SDImageCache sharedImageCache]cleanDisk];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, KScreenHeight/3, KScreenWidth, 30)];
//    label.backgroundColor = [UIColor greenColor];
    label.text = [NSString stringWithFormat:@"清除缓存%.2fM",totalSize];
    label.font = [UIFont boldSystemFontOfSize:18];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor redColor];
    label.alpha = 0;
    [self.view addSubview:label];

    [UIView animateWithDuration:2 animations:^{
        label.alpha = 1;
    } completion:^(BOOL finished) {
        if (finished) {
            [UIView animateWithDuration:2 animations:^{
                label.alpha = 0;
            }];
        }
    }];
    //
    //}
}



// 头像和名字的更改
- (void)setIconAndNameView
{
    self.iconAndNameView = [[UIView alloc]initWithFrame:CGRectMake((KScreenWidth - 300)/2, 100/2, 300, 400)];
    self.iconAndNameView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.iconAndNameView];
    // 头像
    self.iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(150/2, 50/2, 150, 150)];
    self.iconImage.userInteractionEnabled = YES;
    self.iconImage.layer.cornerRadius = 150/2;
    [self.iconImage.layer setMasksToBounds:YES];
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:self.mineModel.userImageStr] placeholderImage:[UIImage imageNamed:@"icon"]];
    [self.iconAndNameView addSubview:self.iconImage];
    
    UITapGestureRecognizer *iconTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(iconTap:)];
    [self.iconImage addGestureRecognizer:iconTap];
    
    
    // 名字
    /*
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 200, 60, 30)];
    label.text = @"昵称";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = KColor;
    [self.iconAndNameView addSubview:label];
    
    self.nameTF = [[UITextField alloc]initWithFrame:CGRectMake(80, 200, 200, 30)];
    self.nameTF.placeholder = self.mineModel.otherName;
    self.nameTF.backgroundColor = KMyColor;
    [self.iconAndNameView addSubview:self.nameTF];
    */
    
    // 确定更改的button
    UIButton *determineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    determineBtn.frame = CGRectMake(170, 270, 100, 30);
    determineBtn.backgroundColor = KColor;
    [determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    determineBtn.layer.cornerRadius = 10;
    determineBtn.layer.masksToBounds = YES;
    [determineBtn addTarget:self action:@selector(determinBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.iconAndNameView addSubview:determineBtn];
    
    // 确定更改的button
    UIButton *defBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    defBtn.frame = CGRectMake(40, 270, 100, 30);
    defBtn.backgroundColor = KColor;
    [defBtn setTitle:@"取消" forState:UIControlStateNormal];
    defBtn.layer.cornerRadius = 10;
    defBtn.layer.masksToBounds = YES;
    [defBtn addTarget:self action:@selector(defBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.iconAndNameView addSubview:defBtn];

}

// 更改头像图片
- (void)iconTap:(UITapGestureRecognizer *)tap
{
    UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"相机" otherButtonTitles:@"相册", nil];
    [action showInView:self.view];
    
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *picker = [[UIImagePickerController alloc]init];
            picker.delegate = self;
            picker.allowsEditing = YES;
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:picker animated:YES completion:nil];
        }
        else
        {
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"该设备没有摄像工具" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }
    if (buttonIndex == 1)
    {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            UIImagePickerController *picker = [[UIImagePickerController alloc]init];
            picker.delegate = self;
            picker.allowsEditing = self;
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:nil];
        }
    }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSLog(@"ok");
    //  1.将选中的图片赋值给imageView
    //  通过字典的key值来取出对应的value值，value就是选中的图片
    UIImage *image= [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        //  将某一张图片存到相册中
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    }
    //获取时间来命名图片
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970]*1000;
    self.nowTime = [NSString stringWithFormat:@"%f", a];
    NSLog(@"nowTime ==== %@", self.nowTime);
    CGSize imageSize = image.size;
    imageSize.height = 150;
    imageSize.width = 150;
    image = [self imageWithImage:image scaledToSize:imageSize];
    
    [self saveImage:image WithName:[self.nowTime stringByAppendingString:@"icon.jpg"]];
    //给上传图片区域附上图片
    self.iconImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

    //  2.将本界面模态回去，即dismiss
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (NSString *)documentFolderPath
{
    NSLog(@"documentFolderPath ==== %@",[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]);
    return [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
}
//压缩图片封装方法
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}

- (void)saveImage:(UIImage *)tempImage WithName:(NSString *)imageName
{
    NSData* imageData = UIImagePNGRepresentation(tempImage);
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];
    // Now we get the full path to the file
    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
    // and then we write it out
    [imageData writeToFile:fullPathToFile atomically:NO];
}


- (void)determinBtn:(UIBarButtonItem *)btn
{
    
    
    NSString *filePath = [NSString stringWithFormat:@"%@/%@icon.jpg",[self documentFolderPath], self.nowTime];
    NSLog(@"filePath ==== %@", filePath);
    
    [BmobProFile uploadFileWithPath:filePath block:^(BOOL isSuccessful, NSError *error, NSString *filename, NSString *url, BmobFile *file) {
        if (isSuccessful) {
            //返回文件名和url
            BmobUser *bUser = [BmobUser getCurrentUser];
            //BmobObject *bmobObject = [BmobObject objectWithoutDatatWithClassName:@"_User"  objectId:bUser.objectId];
            [bUser setObject:self.nameTF.text forKey:@"otherName"];
            [bUser setObject:file forKey:@"icon"];
            [bUser setObject:self.signTV.text forKey:@"sign"];
            [bUser updateInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
                if (isSuccessful) {
//                    //修改成功后的动作
                    [self.personalTableView reloadData];
//                    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake((KScreenWidth-100)/2, KScreenHeight/5*2, 100, 30)];
//                    label.text = @"数据已更新";
//                    label.alpha = 0;
//                    [self.view addSubview:label];
//                    [UIView animateWithDuration:0.5 animations:^{
//                        label.alpha = 1;
//                    } completion:^(BOOL finished) {
//                        if (finished) {
//                            [UIView animateWithDuration:0.5 animations:^{
//                                label.alpha = 0;
//                                
//                            }];
//                            self.iconAndNameView.hidden = YES;
//                            self.signView.hidden = YES;
//                            self.pwView.hidden = YES;
//                        }
//                    }];
                } else if (error)
                {
                    self.iconAndNameView.hidden = YES;
                    self.signView.hidden = YES;
                    NSLog(@"%@",error);
                } else {
                    NSLog(@"UnKnow error");
                }
            }];
        }
        
    } progress:^(CGFloat progress) {
        NSLog(@"%lf",progress);
    }];
    //修改成功后的动作
    [self.personalTableView reloadData];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake((KScreenWidth-100)/2, KScreenHeight/5*2, 100, 30)];
    label.text = @"数据已更新";
    label.alpha = 0;
    [self.view addSubview:label];
    [UIView animateWithDuration:0.5 animations:^{
        label.alpha = 1;
    } completion:^(BOOL finished) {
        if (finished) {
            [UIView animateWithDuration:0.5 animations:^{
                label.alpha = 0;
                
            }];
            self.iconAndNameView.hidden = YES;
            self.signView.hidden = YES;
            self.pwView.hidden = YES;
        }
    }];
    /*
    //更新
    [bUser setObject:self.nameTF.text forKey:@"otherName"];
//    [bUser setObject:self.iconImage.image forKey:@"userImage"];
    [bUser setObject:self.signTV.text forKey:@"sign"];
    [bUser updateInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
        if (isSuccessful) {
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake((KScreenWidth-100)/2, KScreenHeight/5*2, 100, 30)];
            label.text = @"数据已更新";
            label.alpha = 0;
            [self.view addSubview:label];
            [UIView animateWithDuration:0.5 animations:^{
                label.alpha = 1;
            } completion:^(BOOL finished) {
                if (finished) {
                    [UIView animateWithDuration:0.5 animations:^{
                        label.alpha = 0;
                        
                    }];
                    self.iconAndNameView.hidden = YES;
                    self.signView.hidden = YES;
                    self.pwView.hidden = YES;
                }
            }];
        }
        else
        {
            self.iconAndNameView.hidden = YES;
            self.signView.hidden = YES;
        }
    }];
     */
}

/**
 *  设置用户协议
 */
- (void)setUserTextView:(UITextView *)textView
{
    textView.text = @"用户注册协议一、总则1.1  吃货·上海的所有权和运营权归上海东成西就科技有限公司所有。 1.2  用户在注册之前，应当仔细阅读本协议，并同意遵守本协议后方可成为注册用户。一旦注册成功，则用户与吃货·上海之间自动形成协议关系，用户应当受本协议的约束。用户在使用特殊的服务或产品时，应当同意接受相关协议后方能使用。  1.3 本协议则可由吃货·上海随时更新，用户应当及时关注并同意本站不承担通知义务。本站的通知、公告、声明或其它类似内容是本协议的一部分。二、服务内容2.1 吃货·上海的具体内容由本站根据实际情况提供。 2.2 本站仅提供相关的网络服务，除此之外与相关网络服务有关的设备(如个人电脑、手机、及其他与接入互联网或移动网有关的装置)及所需的费用(如为接入互联网而支付的电话费及上网费、为使用移动网而支付的手机费)均应由用户自行负担。三、用户帐号3.1 经本站注册系统完成注册程序并通过身份认证的用户即成为正式用户，可以获得本站规定用户所应享有的一切权限；未经认证仅享有本站规定的部分会员权限。吃货·上海有权对会员的权限设计进行变更。 3.2 用户只能按照注册要求使用真实姓名，及身份证号注册。用户有义务保证密码和帐号的安全，用户利用该密码和帐号所进行的一切活动引起的任何损失或损害，由用 户自行承担全部责任，本站不承担任何责任。如用户发现帐号遭到未授权的使用或发生其他任何安全问题，应立即修改帐号密码并妥善保管，如有必要，请通知本 站。因黑客行为或用户的保管疏忽导致帐号非法使用，本站不承担任何责任。四、使用规则4.1 遵守中华人民共和国相关法律法规，包括但不限于《中华人民共和国计算机信息系统安全保护条例》、《计算机软件保护条例》、《最高人民法院关于审理涉及计算 机网络著作权纠纷案件适用法律若干问题的解释(法释[2004]1号)》、《全国人大常委会关于维护互联网安全的决定》、《互联网电子公告服务管理规 定》、《互联网新闻信息服务管理规定》、《互联网著作权行政保护办法》和《信息网络传播权保护条例》等有关计算机互联网规定和知识产权的法律和法规、实施 办法。  4.2  用户对其自行发表、上传或传送的内容负全部责任，所有用户不得在本站任何页面发布、转载、传送含有下列内容之一的信息，否则本站有权自行处理并不通知用户： (1)违反宪法确定的基本原则的；  (2)危害国家安全，泄漏国家机密，颠覆国家政权，破坏国家统一的；  (3)损害国家荣誉和利益的；  (4)煽动民族仇恨、民族歧视，破坏民族团结的；  (5)破坏国家宗教政策，宣扬邪教和封建迷信的；  (6)散布谣言，扰乱社会秩序，破坏社会稳定的；  (7)散布淫秽、色情、赌博、暴力、恐怖或者教唆犯罪的；  (8)侮辱或者诽谤他人，侵害他人合法权益的；  (9)煽动非法集会、结社、游行、示威、聚众扰乱社会秩序的；  (10)以非法民间组织名义活动的；(11)含有法律、行政法规禁止的其他内容的。4.3 用户承诺对其发表或者上传于本站的所有信息(即属于《中华人民共和国著作权法》规定的作品，包括但不限于文字、图片、音乐、电影、表演和录音录像制品和电 脑程序等)均享有完整的知识产权，或者已经得到相关权利人的合法授权；如用户违反本条规定造成本站被第三人索赔的，用户应全额补偿本站一切费用(包括但不 限于各种赔偿费、诉讼代理费及为此支出的其它合理费用)；  4.4 当第三方认为用户发表或者上传于本站的信息侵犯其权利，并根据《信息网络传播权保护条例》或者相关法律规定向本站发送权利通知书时，用户同意本站可以自行判断决定删除涉嫌侵权信息，除非用户提交书面证据材料排除侵权的可能性，本站将不会自动恢复上述删除的信息； (1)不得为任何非法目的而使用网络服务系统； (2)遵守所有与网络服务有关的网络协议、规定和程序； (3)不得利用本站进行任何可能对互联网的正常运转造成不利影响的行为； (4)不得利用本站进行任何不利于本站的行为。4.5 如用户在使用网络服务时违反上述任何规定，本站有权要求用户改正或直接采取一切必要的措施(包括但不限于删除用户张贴的内容、暂停或终止用户使用网络服务的权利)以减轻用户不当行为而造成的影响。五、隐私保护5.1 本站不对外公开或向第三方提供单个用户的注册资料及用户在使用网络服务时存储在本站的非公开内容，但下列情况除外：      (1)事先获得用户的明确授权； (2)根据有关的法律法规要求； (3)按照相关政府主管部门的要求； (4)为维护社会公众的利益。     5.2  本站可能会与第三方合作向用户提供相关的网络服务，在此情况下，如该第三方同意承担与本站同等的保护用户隐私的责任，则本站有权将用户的注册资料等提供给该第三方。 5.3 在不透露单个用户隐私资料的前提下，本站有权对整个用户数据库进行分析并对用户数据库进行商业上的利用。六、版权声明6.1 本站的文字、图片、音频、视频等版权均归永兴元科技有限公司享有或与作者共同享有，未经本站许可，不得任意转载。  6.2 本站特有的标识、版面设计、编排方式等版权均属永兴元科技有限公司享有，未经本站许可，不得任意复制或转载。   6.3 使用本站的任何内容均应注明“来源于吃货·上海”及署上作者姓名，按法律规定需要支付稿酬的，应当通知本站及作者及支付稿酬，并独立承担一切法律责任。   6.4 本站享有所有作品用于其它用途的优先权，包括但不限于网站、电子杂志、平面出版等，但在使用前会通知作者，并按同行业的标准支付稿酬。   6.5 本站所有内容仅代表作者自己的立场和观点，与本站无关，由作者本人承担一切法律责任。  6.6 恶意转载本站内容的，本站保留将其诉诸法律的权利。七、责任声明7.1 用户明确同意其使用本站网络服务所存在的风险及一切后果将完全由用户本人承担，吃货·上海对此不承担任何责任。  7.2 本站无法保证网络服务一定能满足用户的要求，也不保证网络服务的及时性、安全性、准确性。   7.3 本站不保证为方便用户而设置的外部链接的准确性和完整性，同时，对于该等外部链接指向的不由本站实际控制的任何网页上的内容，本站不承担任何责任。   7.4 对于因不可抗力或本站不能控制的原因造成的网络服务中断或其它缺陷，本站不承担任何责任，但将尽力减少因此而给用户造成的损失和影响。   7.5 对于站向用户提供的下列产品或者服务的质量缺陷本身及其引发的任何损失，本站无需承担任何责任： (1)本站向用户免费提供的各项网络服务；    (2)本站向用户赠送的任何产品或者服务。 7.6 本站有权于任何时间暂时或永久修改或终止本服务(或其任何部分)，而无论其通知与否，本站对用户和任何第三人均无需承担任何责任。八、附则8.1  本协议的订立、执行和解释及争议的解决均应适用中华人民共和国法律。   8.2  如本协议中的任何条款无论因何种原因完全或部分无效或不具有执行力，本协议的其余条款仍应有效并且有约束力。8.3  本协议解释权及修订权归深圳永兴元科技有限公司所有。";
}

@end
